import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class person_data extends StatefulWidget {
  _person_dataWidgetState createState() => new _person_dataWidgetState();
}

class _person_dataWidgetState extends State<person_data> {
  TextEditingController _pwdcontroller = TextEditingController();
  TextEditingController _usernamecontroller = TextEditingController();
  TextEditingController _confirmcontroller = TextEditingController();
  FocusNode _focusNode_username = FocusNode();
  FocusNode _focusNode_password = FocusNode();
  FocusNode _focusNode_confirm = FocusNode();
  FocusNode _focusNode_email = FocusNode();
  FocusNode _focusNode_qq = FocusNode();
  FocusNode _focusNode_phonenum = FocusNode();
  String _sex = '请选择性别';
  var _backcolor_username = Colors.black;
  var _backcolor_password = Colors.black;
  var _backcolor_confirm = Colors.black;
  var _backcolor_email = Colors.black;
  var _backcolol_qq = Colors.black;
  var _backcolol_phonenum = Colors.black;
  GlobalKey _globalKey_username = new GlobalKey<FormState>();
  bool _isObscure_pwd = true;
  bool _isObscure_confirm = true;
  var _eyeColor_pwd = Colors.grey;
  var _eyeColor_confirm = Colors.grey;
  var _text_user = '';
  var _text_pwd = '';
  var _text_confirm = '';

  void initState() {
    //_globalKey_username.currentState.setState(() {});
    _focusNode_username.addListener(() {
      if (_focusNode_username.hasFocus) {
        setState(() {
          _backcolor_username = Colors.blue;
        });
      } else {
        setState(() {
          _backcolor_username = Colors.black;
        });
      }
    });
    _focusNode_password.addListener(() {
      if (_focusNode_password.hasFocus) {
        setState(() {
          _backcolor_password = Colors.blue;
        });
      } else {
        setState(() {
          _backcolor_password = Colors.black;
        });
      }
    });
    _focusNode_confirm.addListener(() {
      if (_focusNode_confirm.hasFocus) {
        setState(() {
          _backcolor_confirm = Colors.blue;
        });
      } else {
        setState(() {
          _backcolor_confirm = Colors.black;
        });
      }
    });
    _focusNode_email.addListener(() {
      if (_focusNode_email.hasFocus) {
        setState(() {
          _backcolor_email = Colors.blue;
        });
      } else {
        setState(() {
          _backcolor_email = Colors.black;
        });
      }
    });
    _focusNode_qq.addListener(() {
      if (_focusNode_qq.hasFocus) {
        setState(() {
          _backcolol_qq = Colors.blue;
        });
      } else {
        setState(() {
          _backcolol_qq = Colors.black;
        });
      }
    });
    _focusNode_phonenum.addListener(() {
      if (_focusNode_phonenum.hasFocus) {
        setState(() {
          _backcolol_phonenum = Colors.blue;
        });
      } else {
        setState(() {
          _backcolol_phonenum = Colors.black;
        });
      }
    });
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text('不知道起啥名'),
        automaticallyImplyLeading: false,
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.all(16.0),
              child: Text(
                '个人信息',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 28.0,
                  height: 1.2,
                ),
              ),
            ),
            Padding(
                padding: EdgeInsets.only(bottom: 16.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.max,
                  children: <Widget>[
                    Text(
                      '请完善您的个人信息。',
                      style: TextStyle(
                          color: Colors.black, fontSize: 15.0, height: 1.0),
                    ),
                    Text(
                      '了解详情',
                      style: TextStyle(
                          color: Colors.blue, fontSize: 15.0, height: 1.0),
                    )
                  ],
                )),
            Form(
              autovalidate: true,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.fromLTRB(16.0, 10.0, 16.0, 10.0),
                    child: Center(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(
                                width: 3.0,
                                color: _backcolor_username,
                              ),
                              borderRadius: const BorderRadius.all(
                                  const Radius.circular(12.0)),
                            ),
                            child: TextField(
                              //key: _globalKey,
                              onChanged: (text) {
                                if (text.trim().length == 0) {
                                  _text_user = '真实姓名不能为空';
                                  _backcolor_username = Colors.red;
                                } else {
                                  _text_user = '';
                                  _backcolor_username = Colors.blue;
                                }
                              },
                              controller: _usernamecontroller,
                              focusNode: _focusNode_username,
                              autofocus: false,
                              cursorColor: const Color(0xFFFF6B47),
                              cursorWidth: 1.0,
                              style: TextStyle(
                                color: Color(0xFF4A4A4A),
                                fontSize: 16.0,
                              ),
                              decoration: InputDecoration(
                                  border: InputBorder.none,
                                  fillColor: const Color(0xFFFF5F5F5),
                                  isDense: true,
                                  filled: true,
                                  labelText: "真实姓名",
                                  hintText: "请输入真实姓名",
                                  hintStyle: TextStyle(
                                    color: Color(0xFF9B9B9B),
                                    fontSize: 16.0,
                                  ),
                                  prefixIcon: Icon(Icons.person)),
                              /* validator: (v) {
                                    return v.trim().length > 0 ? null : "用户名不能为空";
                                  },*/
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 16.0),
                            child: Text(
                              '$_text_user',
                              key: _globalKey_username,
                              style: TextStyle(
                                fontSize: 12.0,
                                color: Colors.red,
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(16.0, 10.0, 16.0, 10.0),
                    child: Center(
                        child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Container(
                          decoration: BoxDecoration(
                            border: Border.all(
                              width: 3.0,
                              color: _backcolor_password,
                            ),
                            borderRadius: const BorderRadius.all(
                                const Radius.circular(12.0)),
                          ),
                          child: TextField(
                            // key: _globalKey,
                            focusNode: _focusNode_password,
                            onChanged: (text) {
                              if (text.trim().length == 0) {
                                setState(() {
                                  _text_pwd = '学号不能为空';
                                  _backcolor_password = Colors.red;
                                });
                              } else {
                                setState(() {
                                  _text_pwd = '';
                                  _backcolor_password = Colors.blue;
                                  print(text);
                                });
                              }
                            },
                            autofocus: false,
                            cursorColor: const Color(0xFFFF6B47),
                            cursorWidth: 1.0,
                            controller: _pwdcontroller,
                            style: TextStyle(
                              color: Color(0xFF4A4A4A),
                              fontSize: 16.0,
                            ),
                            decoration: InputDecoration(
                                border: InputBorder.none,
                                fillColor: const Color(0xFFFF5F5F5),
                                isDense: true,
                                filled: true,
                                labelText: "学号",
                                hintText: "请输入学号",
                                hintStyle: TextStyle(
                                  color: Color(0xFF9B9B9B),
                                  fontSize: 16.0,
                                ),
                                prefixIcon: Icon(Icons.dialpad)),
                          ),
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 16.0),
                          child: Text(
                            '$_text_pwd',
                            style: TextStyle(
                              fontSize: 12.0,
                              color: Colors.red,
                            ),
                          ),
                        )
                      ],
                    )),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(80.0, 1.0, 16.0, 10.0),
                    child: Wrap(
                      spacing: 100.0,
                      children: <Widget>[
                        Text(
                          '性别',
                          style: TextStyle(
                            fontSize: 19.0,
                          ),
                        ),
                        Container(
                          child: new GestureDetector(
                            child: Text(
                              '$_sex',
                              style: TextStyle(fontSize: 19.0),
                            ),
                            onTap: () {
                              showDialog<Null>(
                                  context: context,
                                  builder: (BuildContext context) {
                                    return new SimpleDialog(
                                      title: Text('请选择性别'),
                                      children: <Widget>[
                                        RadioListTile<String>(
                                          value: '男性',
                                          title: Text('男性'),
                                          groupValue: _sex,
                                          onChanged: (value) {
                                            setState(() {
                                              _sex = value;
                                            });
                                            Navigator.pop(context);
                                          },
                                        ),
                                        RadioListTile<String>(
                                          value: '女性',
                                          title: Text('女性'),
                                          groupValue: _sex,
                                          onChanged: (value) {
                                            setState(() {
                                              _sex = value;
                                            });
                                            Navigator.pop(context);
                                          },
                                        ),
                                        RadioListTile<String>(
                                          value: '私密',
                                          title: Text('私密'),
                                          groupValue: _sex,
                                          onChanged: (value) {
                                            setState(() {
                                              _sex = value;
                                            });
                                            Navigator.pop(context);
                                          },
                                        ),
                                      ],
                                    );
                                  });
                            },
                          ),
                        )
                      ],
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(16.0, 10.0, 16.0, 10.0),
                    child: Center(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(
                                width: 3.0,
                                color: _backcolor_email,
                              ),
                              borderRadius: const BorderRadius.all(
                                  const Radius.circular(12.0)),
                            ),
                            child: TextField(
                              // key: _globalKey,
                              //controller: _confirmcontroller,
                              focusNode: _focusNode_email,
                              autofocus: false,
                              cursorColor: const Color(0xFFFF6B47),
                              cursorWidth: 1.0,
                              style: TextStyle(
                                color: Color(0xFF4A4A4A),
                                fontSize: 16.0,
                              ),
                              decoration: InputDecoration(
                                  border: InputBorder.none,
                                  fillColor: const Color(0xFFFF5F5F5),
                                  isDense: true,
                                  filled: true,
                                  labelText: "邮箱(选填)",
                                  hintText: "请输入邮箱",
                                  hintStyle: TextStyle(
                                    color: Color(0xFF9B9B9B),
                                    fontSize: 16.0,
                                  ),
                                  prefixIcon: Icon(Icons.email)),
                              /* validator: (v){
                           return v.trim().toString()==_pwdcontroller.text.toString()?null:"两次密码输入不一致";
                          },*/
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 16.0),
                            child: Text(
                              '$_text_confirm',
                              style: TextStyle(
                                fontSize: 12.0,
                                color: Colors.red,
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(16.0, 10.0, 16.0, 10.0),
                    child: Center(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(
                                width: 3.0,
                                color: _backcolol_phonenum,
                              ),
                              borderRadius: const BorderRadius.all(
                                  const Radius.circular(12.0)),
                            ),
                            child: TextField(
                              // key: _globalKey,
                              // controller: _confirmcontroller,

                              focusNode: _focusNode_phonenum,
                              autofocus: false,
                              cursorColor: const Color(0xFFFF6B47),
                              cursorWidth: 1.0,
                              style: TextStyle(
                                color: Color(0xFF4A4A4A),
                                fontSize: 16.0,
                              ),
                              decoration: InputDecoration(
                                  border: InputBorder.none,
                                  fillColor: const Color(0xFFFF5F5F5),
                                  isDense: true,
                                  filled: true,
                                  labelText: "手机号码(选填)",
                                  hintText: "请输入手机号码",
                                  hintStyle: TextStyle(
                                    color: Color(0xFF9B9B9B),
                                    fontSize: 16.0,
                                  ),
                                  prefixIcon: Icon(Icons.phone)),
                              /* validator: (v){
                           return v.trim().toString()==_pwdcontroller.text.toString()?null:"两次密码输入不一致";
                          },*/
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 16.0),
                            child: Text(
                              '$_text_confirm',
                              style: TextStyle(
                                fontSize: 12.0,
                                color: Colors.red,
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(16.0, 10.0, 16.0, 10.0),
                    child: Center(
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(
                                width: 3.0,
                                color: _backcolol_qq,
                              ),
                              borderRadius: const BorderRadius.all(
                                  const Radius.circular(12.0)),
                            ),
                            child: TextField(
                              // key: _globalKey,
                              //controller: _confirmcontroller,

                              focusNode: _focusNode_qq,
                              autofocus: false,
                              cursorColor: const Color(0xFFFF6B47),
                              cursorWidth: 1.0,
                              style: TextStyle(
                                color: Color(0xFF4A4A4A),
                                fontSize: 16.0,
                              ),
                              decoration: InputDecoration(
                                  border: InputBorder.none,
                                  fillColor: const Color(0xFFFF5F5F5),
                                  isDense: true,
                                  filled: true,
                                  labelText: "QQ号(选填)",
                                  hintText: "请输入QQ号",
                                  hintStyle: TextStyle(
                                    color: Color(0xFF9B9B9B),
                                    fontSize: 16.0,
                                  ),
                                  prefixIcon: Icon(Icons.mood)),
                              /* validator: (v){
                           return v.trim().toString()==_pwdcontroller.text.toString()?null:"两次密码输入不一致";
                          },*/
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 16.0),
                            child: Text(
                              '$_text_confirm',
                              style: TextStyle(
                                fontSize: 12.0,
                                color: Colors.red,
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Padding(
              padding: EdgeInsets.only(bottom: 60.0),
              child: Wrap(
                spacing: 85.0,
                children: <Widget>[
                  FlatButton(
                    color: Color(0x000001),
                    colorBrightness: Brightness.dark,
                    textColor: Colors.blue,
                    child: Text('返回'),
                    //textColor: Colors.white,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20.0)),
                    onPressed: () {
                      Navigator.popAndPushNamed(context, 'register');
                    },
                  ),
                  RaisedButton(
                    color: Colors.blue,
                    highlightColor: Colors.blue[700],
                    colorBrightness: Brightness.dark,
                    child: Text('下一步'),
                    //textColor: Colors.white,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20.0)),
                    onPressed: () {
                      bool flag = true;
                      if (_usernamecontroller.text.trim().length == 0) {
                        setState(() {
                          _backcolor_username = Colors.red;
                          _text_user = '真实姓名不能为空';
                        });
                      } else {
                        setState(() {
                          _text_user = '';
                          _backcolor_username = Colors.black;
                        });
                        if (_pwdcontroller.text.trim().length == 0) {
                          setState(() {
                            _backcolor_password = Colors.red;
                            _text_pwd = '学号不能为空';
                          });
                        } else {
                          setState(() {
                            _text_pwd = '';
                            _backcolor_password = Colors.black;
                          });
                          Navigator.pushNamed(context, "First");
                          //  Navigator.popUntil(context,ModalRoute.withName("register"));
                          Navigator.of(context).pushNamedAndRemoveUntil(
                              'First', ModalRoute.withName('register'));
                        }
                      }
                    },
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
